package com.mrduan.otgfilemanager.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by duany on 2018/5/12.
 */

public class CalendarUtil {
    //时间戳转字符串
    public static String getStrTime(Calendar calendar){
        long timeStamp = calendar.getTimeInMillis();
        String timeString = null;
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd");
        timeString = sdf.format(new Date(timeStamp));//单位秒
        return timeString;
    }

    public static String getWeekDay(Calendar calendar) {
        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
        String weekStrings[] = {"周日","周一","周二","周三","周四","周五","周六"};
        String weekString = weekStrings[dayOfWeek-1];
        return weekString;
    }

    public static String timesAsCustom(String time,String like) {
        SimpleDateFormat sdr = new SimpleDateFormat(like);
        long i = Long.parseLong(time);
        String times = sdr.format(new Date(i));
        return times;
    }

    public static String timesAsCustom(String like) {
        SimpleDateFormat sdr = new SimpleDateFormat(like);
        String times = sdr.format(new Date(Calendar.getInstance().getTimeInMillis()));
        return times;
    }

}
